package com.tools.controller;

import com.tools.entity.NBAPlayer;
import com.tools.service.PlayerService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

@RestController
public class NBAPlayerController {

    @Resource
    private PlayerService playerService;


    @RequestMapping("/import")
    public List<NBAPlayer> searchTerm(){
        try {
           playerService.importAll();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    @RequestMapping("/del")
    public List<NBAPlayer> del(){
        try {
            playerService.deleteAll();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    @RequestMapping("/search/term")
    public List<NBAPlayer> searchTerm(String name,String query){
        List<NBAPlayer> list = null;
        try {
            list = playerService.termQuery(name, query);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return list;
    }
    @RequestMapping("/search/match")
    public List<NBAPlayer> searchMatch(String name,String query){
        List<NBAPlayer> list = null;
        try {
            list = playerService.matchQuery(name, query);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return list;
    }


}
